﻿ #region Disclaimer/Info
 
 /////////////////////////////////////////////////////////////////////////////////////////////////
 //
 //   File:		TagCloudHelper.cs
 //   Website:		http://dexterblogengine.com/
 //   Authors:		http://dexterblogengine.com/About.ashx
 //   Rev:		1
 //   Created:		19/01/2011
 //   Last edit:		19/01/2011
 //   License:		GNU Library General Public License (LGPL)
 // 
 //   For updated news and information please visit http://dexterblogengine.com/
 //   Dexter is hosted to Codeplex at http://dexterblogengine.codeplex.com
 //   For any question contact info@dexterblogengine.com
 //
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 #endregion

using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Dexter.DataTransferObject;
using Dexter.Dependency;
using Dexter.Services;
using Dexter.Web.Controls;

namespace Dexter.Web.Mvc.Helpers {
	public static class TagCloudHelper {
		public static MvcHtmlString TagCloud ( this HtmlHelper helper, IEnumerable<TagDto> tags ) {
			return TagCloud ( helper , tags , null );
		}

		public static MvcHtmlString TagCloud ( this HtmlHelper helper, IEnumerable<TagDto> tags, string ulClass ) {
			var u = DexterContainer.Resolve<IUrlBuilder> ( );

			var tagCloud = new TagCloud ( tags.Select ( x => new TagInfo ( x.Name, x.Count, 1 ) ).ToList ( ), u );
			tagCloud.UnorderedListClassName = ulClass;
			return MvcHtmlString.Create ( tagCloud.ToString ( ) );
		}

		public static MvcHtmlString TagCloud ( this HtmlHelper helper, IEnumerable<TagDto> tags, bool alfabeticSort ) {
			return TagCloud ( helper, tags, false, null );
		}

		public static MvcHtmlString TagCloud ( this HtmlHelper helper, IEnumerable<TagDto> tags, bool alfabeticSort, string ulClass ) {
			var u = DexterContainer.Resolve<IUrlBuilder> ( );

			var tagCloud = new TagCloud ( tags.Select ( x => new TagInfo ( x.Name , x.Count , 1 ) ).ToList ( ) , u );
			tagCloud.UnorderedListClassName = ulClass;
			return MvcHtmlString.Create ( tagCloud.ToString ( alfabeticSort ) );
		}
	}
}
